import sys
import pygame
from myClass import *
def CarMove(CarRect=None, Target=1, speed=1,locationA=0,CheckPoint=Point(),isFinish=None):
	# if locationA==-1:
	# 	if CarRect.x <= CheckPoint.x-(CheckPoint.x-startPoint.x)/3:
	# 		CarRect.x += Target * speed * 3
	# 		CarRect.y -= Target * speed
	# 		isFinish = 0
	# 	else:
	# 		isFinish=1
	if locationA==0:
		if Target==1:
			if CarRect.x <= CheckPoint.x:
				CarRect.x += Target * speed * 3
				CarRect.y -= Target * speed
				isFinish = 0
			else:
				isFinish = 1

		if Target==-1:
			if CarRect.x >= CheckPoint.x:
				CarRect.x += Target * speed * 3
				CarRect.y -= Target * speed
				isFinish = 0
			else:
				isFinish = 1

	if locationA==1:
		if Target == 1:
			if CarRect.x <= 1200:
				CarRect.x += Target * speed * 3
				CarRect.y -= Target * speed
				isFinish = 0
			else:
				isFinish = 1
		if Target == -1:
			if CarRect.x >= -400:
				CarRect.x += Target * speed * 3
				CarRect.y -= Target * speed
				isFinish = 0
			else:
				isFinish = 1

	if locationA == 2:
		if Target == -1:
			if CarRect.x <= 1200:
				CarRect.x += -1*Target * speed * 3
				CarRect.y -= -1*Target * speed
				isFinish = 0
			else:
				isFinish = 1
		if Target == 1:
			if CarRect.x >= -400:
				CarRect.x += -1*Target * speed * 3
				CarRect.y -= -1*Target * speed
				isFinish = 0
			else:
				isFinish = 1








	return CarRect,isFinish

    # tagret=1为进，tagret=2为出
def flagRotate(flag1=True,inangle=0,flag1direction=1,InPole=None,image_raw=None):

	inangle += 1 * flag1direction
	InPole = pygame.transform.rotate(image_raw, inangle)
	return flag1, inangle, flag1direction, InPole

def judgeTheState(locationState0,locationState1,waitingQuene,AnimationQuene,locationCar,flag2):
	i=0
	if locationState0 == False:
		if waitingQuene.is_empty() == False:
			locationCar[0] = waitingQuene.dequeue()


			i+=1
			# 动画加载
			tempAnime = Animation(locationCar[0], -1, 0)
			AnimationQuene.enqueue(tempAnime)



			locationState0 = True
			print("等待队列车辆进入位置1")
	if locationState0 == True:
		if locationState1 == False:
			locationCar[1] = locationCar[0]
			# 动画加载
			tempAnime = Animation(locationCar[0], 0, 1)
			AnimationQuene.enqueue(tempAnime)

			locationCar[0] = None
			locationState1 = True
			locationState0 = False
			i += 1

			print("位置1车辆进入位置2")

	# 动画播放

	if locationState1 == True:
		if flag2:
			# 动画加载
			tempAnime = Animation(locationCar[1], 1, 2)
			AnimationQuene.enqueue(tempAnime)
			locationCar[1] = None



			flag2 = False
			locationState1 = False
			i += 1

			print("位置2车辆出")

	return locationState0, locationState1, waitingQuene,AnimationQuene, locationCar, flag2, i





